package org.batyrov.equery.server;

import java.io.BufferedReader;
import java.net.Socket;

/**
 * Created by IntelliJ IDEA.
 * User: sulic
 * Date: 26.02.2010
 * Time: 9:59:46
 * To change this template use File | Settings | File Templates.
 */
public class InReader extends Thread {
    BufferedReader socketReader;
    Socket _socket;
    boolean flag = true;

    public InReader(BufferedReader socketReader, Socket _socket) {
        this.socketReader = socketReader;
        this._socket = _socket;
    }

    public synchronized void run() {
        while (flag) {
            try {
                if (socketReader.readLine().equals("goodbye"))
                    Server.removeByQuery(_socket.getRemoteSocketAddress());
            } catch (Exception e) {
                System.out.println("Client is closed without send");
                Server.removeByQuery(_socket.getRemoteSocketAddress());
            }
        }
    }

    public void close() {
        flag = false;
    }
}
